<?php
namespace Common\Model;
use Think\Model;

/**
* 模块
*/
class DatasheetModel extends Model{
	
	protected $tableName = 'datasheet';

	protected $_validate = array(
		array('d_name','require','数据表名称不能为空！'), //空验证  默认情况下用正则进行验证
		//array('mo_desc','require','模块描述不能为空！')
	);


	/**
	 * 查询多条数据
	 */
	public function selectDatasheet($where=array(),$order='',$page_size='',$parametar=array()){
		/*if($where['status']==''||empty($where['status'])){
			$where['status'] = array('neq','9');
		}*/
		if($page_size==''){
			$result = $this->where($where)->order($order)->select();
		}else{
			$count = $this->where($where)->count();
			$page = new \Think\Page($count,$page_size);
			$page->parameter = $parameter;
			$page->setConfig('theme',"<ul class='pagination'>
                <li>%TOTAL_ROW%</li>
                <li>%UP_PAGE%</li>
                %LINK_PAGE%
                <li>%DOWN_PAGE%</li>
                </ul>"
            );
            $show = $page->show();
            $list = $this->where($where)->order($order)->limit($page->firstRow,$page_size)->select();
            $result = array('page'=>$show,'list'=>$list);
		}
		return $result;
	}

	/**
	 * 增加数据
	 */
	public function addDatasheet($data){
		if(empty($data)){
			return false;
		}
		$result = $this->data($data)->add();
		return $result;
	}


	/**
	 * 查询一条数据
	 */
	public function findDatasheet($where){
		/*if($where['status']==''||empty($where['status'])){
			$where['status'] = array('neq','9');
		}*/
		$result = $this->where($where)->find();
		return $result;
	}

	/**
	 * 编辑
	 */
	public function editDatasheet($where=array(),$data=array()){
        /*if(empty($where) || empty($data)){
            return false;
        }*/
        $result = $this->where($where)->data($data)->save();
        return $result;
    }

    /**
     * 删除
     */
    public function deleteDatasheet($where=array()){
    	if(empty($where)){
    		return false;
    	}
    	$result = $this->where($where)->delete();
    	return $result;
    }

}

?>